/*
 * Created on 2005-1-24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.nauu.atombuilder.parts;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.CompoundSnapToHelper;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.SnapToGeometry;
import org.eclipse.gef.SnapToGrid;
import org.eclipse.gef.SnapToGuides;
import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editpolicies.SnapFeedbackPolicy;
import org.eclipse.gef.rulers.RulerProvider;

import com.nauu.atombuilder.figures.ColbarFigure;
import com.nauu.atombuilder.figures.NodeFigure;
import com.nauu.atombuilder.modle.Colbar;
import com.nauu.atombuilder.modle.Connection;
import com.nauu.atombuilder.modle.Diagram;
import com.nauu.atombuilder.modle.Node;
import com.nauu.atombuilder.policies.ContainerHighlightEditPolicy;
import com.nauu.atombuilder.policies.DiagramLayoutEditPolicy;
import com.nauu.atombuilder.policies.FormDiagramLayoutEditPolicy;
import com.nauu.atombuilder.policies.NodeDirectEditPolicy;
import com.nauu.atombuilder.policies.NodeEditPolicy;
import com.nauu.atombuilder.policies.NodeGraphicalNodeEditPolicy;

/**
 * @author nauu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ColbarPart extends AbstractGraphicalEditPart implements PropertyChangeListener {

    protected List getModelChildren() {
        return ((Colbar) this.getModel()).getItems();
    }

    
    public void activate() {
        super.activate();
        ((Colbar) getModel()).addPropertyChangeListener(this);
    }

    public void deactivate() {
        super.deactivate();
        ((Colbar) getModel()).removePropertyChangeListener(this);
    }
    
    public void propertyChange(PropertyChangeEvent evt) {
        String prop = evt.getPropertyName();
        if (Diagram.PROP_NODE.equals(prop)){
        	refreshChildren();
        }
    }

    protected IFigure createFigure() {
        Figure figure = new ColbarFigure();
        return figure;
    }

    protected void refreshVisuals() {
        Node node = (Node) getModel();
        Point loc = node.getLocation();
        Dimension size = node.getSize();
        Rectangle rectangle = new Rectangle(loc, size);
        ((NodeFigure) this.getFigure()).setName(((Node) this.getModel()).getName());
        ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), rectangle);
        
    }
    
    protected void createEditPolicies() {
    	 installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new NodeDirectEditPolicy());
         installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeEditPolicy());
         installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new NodeGraphicalNodeEditPolicy());
//        installEditPolicy(EditPolicy.LAYOUT_ROLE, new FormDiagramLayoutEditPolicy());
//        installEditPolicy("Snap Feedback", new SnapFeedbackPolicy());
//        installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,new ContainerHighlightEditPolicy());
        
    }

}